import router from './index'
import store from '../store'
import {Message} from 'element-ui'

// 白名单
const whiteList = ["/login","/admin/login","/home"]

router.beforeEach((to,from,next)=>{
    const {id,token} = store.state.user
    if(id&&token){
        // 如果已经登录直接放行
        next()
    }else{
        for(let i=0;i<whiteList.length;i++){
            if(to.path.indexOf(whiteList[i])!== -1){
                // 白名单内地址，放行
                next()
                return 
            }
        }
        Message.error("未登录，请先登录后再尝试")
        next("/admin/login")
    }
    
})